package com.settlement.system.controller;

import com.settlement.system.csv.CsvExportBuilder;
import com.settlement.system.csv.CsvExportUtil;
import com.settlement.system.common.enums.ExcelFileType;
import com.settlement.system.common.exception.ServiceException;
import com.settlement.system.model.entity.common.TblJdWalletSerial;
import com.settlement.system.service.IBaseService;
import com.settlement.system.service.ITblJdWalletSerialService;
import com.settlement.system.service.csv.DateSpiltCsvDatas;
import com.settlement.system.common.util.common.FasUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.Map;

/**
 * 收退款-京东钱包流水 前端控制器
 * @author Ximi
 * @since 2020-06-15
 */

@Api(tags = "京东-钱包流水",description = "京东-钱包流水")
@RestController
@RequestMapping("/jd/wallet_serial")
public class TblJdWalletSerialController extends MergeApiExcelController<TblJdWalletSerial, Map<String,Object>> {

    @Value("${system.export-root.path}")
    private String exportRootPath;

    @Resource
    private ITblJdWalletSerialService tblJdWalletSerialService;

    @Override
    public IBaseService init() {
        return tblJdWalletSerialService;
    }

    @Override
    public Class<?> getModelClass() {
        return TblJdWalletSerial.class;
    }

    @Override
    protected void setParamsModel(Map<String, Object> model) {
        FasUtil.formatInQueryCondition(model,"shopName");
        super.setParamsModel(model);
    }

    @Override
    protected void setFootModel(Map<String, Object> result, Map<String, Object> model) throws ServiceException {
        result.put("foot",tblJdWalletSerialService.getFoot(model));
    }

    @Override
    public void exportExcelPost(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> params) throws Exception {
        setParamsModel(params);
        String fileName = "京东-钱包流水";
        String path = exportRootPath + System.currentTimeMillis() + File.separator;
        CsvExportUtil.createCsv()
                .headClass(TblJdWalletSerial.class)
                .fileName(fileName)
                .fileType(ExcelFileType.XLSX)
                .model(CsvExportBuilder.MULTI_ZIP_MODEL)
                .parentPath(path)
                .csvDatas(new DateSpiltCsvDatas(tblJdWalletSerialService, params))
                .export(request, response);
    }
}

